(function (w) {
    w.Swap = function (options) {
        let target = options.target;
        let items = options.items;
        let ul = document.createElement('ul');
        //添加所有
        items.forEach(element => {
            let li = document.createElement('li');
            $(li).css(element);
            ul.append(li);
        });
        //加一张
        let li = document.createElement('li');
        $(li).css(items[0]);
        ul.append(li);
        this.jqDom = $(target);
        this.jqDom.append(ul);
        this.jqDom.css({
            overflow: "hidden"
        });
        let firstjqDom = this.jqDom.find(":first");
        let lis = firstjqDom.find("li");
        let height = this.jqDom.height();
        let width = this.jqDom.width();
        firstjqDom.css({
            width: width * lis.length + "px",
            height: height + "px",
            position: "relative"
        });
        $.each(lis, function () {
            $(this).css({
                width: width + "px",
                height: height + "px",
                listStyleType: "none",
                float: "left",
                position: "relative"
            });
        });
        //自动滚动 滚动时间，滚动间隔
        this.scroll = function (s) {
            let length = items.length;
            let nowP = 0;
            setInterval(() => {
                if (nowP <= length) {
                    this.scrollTo('left', nowP, s);
                    nowP++;
                } else {
                    nowP = 0;
                    firstjqDom.css({
                        left: "0px"
                    })
                }
            }, s + 500);
        }
        this.scrollTo = function (f, p, s) {
            f = f == 'left' ? -1 : 1;
            p = isNaN(p) ? 1 : p;
            let width = f * p * this.jqDom.width();
            this.jqDom.find(":first").css({
                'transition-timing-function': 'linear',
                'transition-duration': s + 'ms',
                'transform': 'translate3d(' + width + 'px,0px,0px)'
            });
        }
    }
})(window)